<!--
  Copyright 2020 The Chromium Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.
-->
<script>
(async () => {
  const importObj = {
    env: {
      memory: new WebAssembly.Memory({
        initial: 1,
        maximum: 1,
      }),
      __memory_base: 1024,
      table: new WebAssembly.Table({
        initial: 2,
        maximum: 2,
        element: 'anyfunc',
      }),
      printf: function(s) { console.log(s); },
      printfI: function(s) { console.log(s); }
    }
  };

  const pagename = window.location.pathname.split('/').pop();
  const modulename = pagename.substr(0, pagename.length - 5) + '.wasm';

  const instance = await WebAssembly.instantiateStreaming(fetch(modulename), importObj);
  window.main = instance.instance.exports.Main;
  main();
})();
</script>
